home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15265 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.4 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: PUBLIC / PRIVATE
  5. Date: 17 Apr 1996 19:07:54 -0700
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4l485qINN14r@keats.ugrad.cs.ubc.ca>
  8. References: <4l3k8d$hkp@mulga.cs.mu.OZ.AU>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <4l3k8d$hkp@mulga.cs.mu.OZ.AU>,
  12. Falchion <simc@mundil.cs.mu.OZ.AU> wrote:
  13.  >I'm analysing some C source code and I've
  14.  >come across PUBLIC and PRIVATE keywords
  15.  >
  16.  >eg PUBLIC char * app_name = "Lynx";
  17.  >
  18.  >   PRIVATE void HTFWriter_write ARGS3(HTSteam, *, me, CONST char*,
  19.  >                    s, int, l) { fwrite(s, 1, l, me->fp) }
  20.  >
  21.  >
  22.  >I though C didn't have PUBLIC or PRIVATE ?
  23.  
  24. Ha ha. They are just #define symbols. The ARGS3, and their upper case should
  25. have put you onto this: C would never have keywords that are all caps. Heck, we
  26. would look like we are shouting at the compiler!
  27.  
  28. The Linux kernel uses a similar scheme. For debugging purposes, you name your
  29. static variables Static. This makes them external in fact when you are
  30. debugging, but evaluates to the actual "static" keyword when you make a
  31. production build. The whole purpose is to make symbols that are normally
  32. private to a module externally visible for debugging purposes, in that case.
  33. Most likely, PUBLIC just expands to nothing, and PRIVATE to "static".
  34.  
  35.  >It definitely doesn't look like C++ source code - it looks like
  36.  >C code with PUBLIC and PRIVATE keywords scattered everywhere.
  37.  >
  38.  >2nd question:
  39.  >   PRIVATE void HTFWriter_write ARGS3(HTSteam, *, me, CONST char*,
  40.  >                    s, int, l) { fwrite(s, 1, l, me->fp) }
  41.  >
  42.  >   What is the ARGS3 ?
  43.  
  44. It is another preprocessor macro. The idea here is probably to support
  45. old-style C compilers. If you have old-style C, ARGS3(HtSteam, ...) will
  46. probably evalute to an old-style declaration. In ANSI environments, it will
  47. expand into a new-style declaration.
  48.  
  49. The above mechanism will fail miserably for function pointers, in which the
  50. declarator identifier cannot be so neatly disentangled from the rest of the
  51. declaration.
  52.  
  53. This looks very familiar. The CERN HTTPD server has almost exactly the same
  54. kind of macro.
  55.  
  56.  >   I'm accustomed to 
  57.  >    return_type function_name(args) { ... }
  58.  
  59. Pre-processor tricks can make a C program look like it is in another language.
  60. That's parly why upper-case is used for macro names---it's a warning sign that
  61. something weird is happening.
  62.